Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const for new_static #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

XuJiandong
Copy link

Make it possible:

#[global_allocator]
static ALLOC: FixedAlloc = FixedAlloc::new_static();

@xxuejie
Copy link
Owner

xxuejie commented Apr 25, 2023

I actually realized it here, but I think the API in general, needs bigger change. The reason does not have to do with new_static, it's rather new. The original idea, is that one can do either of the following:

#[global_allocator]
static ALLOC: FixedAlloc = FixedAlloc::new_static();

or:

#[global_allocator]
static ALLOC: FixedAlloc = FixedAlloc::new(buf_ptr, 1024 * 1024, true);

Even though we can mark new_static as const, there is not way we can mark new as const, since new calls an unsafe C function.

So personally I kinda wanted to simply remove new_static and new, and just wrap the following in a macro:

#[global_allocator]
static ALLOC: FixedAlloc = FixedAlloc{};

Simply put, I don't think it is a good API design if we simply put const on new_static, it works around the issue in some cases, but it does not touch the root problem

@XuJiandong
Copy link
Author

#[global_allocator]
static ALLOC: FixedAlloc = FixedAlloc{};

is fine. And call initialize function at the first time of malloc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants